import './SearchBox.scss'
import { useEventEmitter } from 'ahooks'
import { FormTemplate } from '../../Utils/FormTemp'

const SearchBox = ({ data, ModalEvent, Off }) => {
    const { columns, initValue } = data
    const FromEvent = useEventEmitter()
    FromEvent.useSubscription(val => {
        const { type, data } = val
        if (type === 'Added') ModalEvent.emit({ type: 'Search', data })
        else ModalEvent.emit({ type: 'SeaRef' })
        Off()
    })

    return (
        <div className='SearchBox'>
            <FormTemplate columns={columns} ModalEvent={FromEvent} init={initValue} onSearch />
        </div>
    )
};

export default SearchBox